<template>
  <el-dialog title="分配橘色" :visible="showRoleDialog" @close="btnCancel">
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in checkList" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <el-row slot="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button type="primary" size="smll" @click="addRole">确定</el-button>
        <el-button size="smll" @click="btnCancel">取消</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import { getRoleList } from '@/api/setting'
import { getRoleById } from '@/api/user'
import { addRole } from '@/api/employees'
export default {
  props: {
    showRoleDialog: {
      type: Boolean,
      default: false
    },
    userId: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      checkList: [],
      roleIds: []
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    // 获取角色列表信息
    async getRoleList() {
      const { rows } = await getRoleList({ page: 1, size: 20 })
      this.checkList = rows
      console.log(this.checkList, this.showDialog, 222)
    },
    // 获取用户角色信息
    async getRoleById(id) {
      const { roleIds } = await getRoleById(id)
      console.log(roleIds, 991)
      this.roleIds = roleIds
    },
    // 给用户分配角色
    async addRole() {
      await addRole({ id: this.userId, roleIds: this.roleIds })
      this.btnCancel()
    },
    btnCancel() {
      this.roleIds = []
      this.$emit('update:showRoleDialog', false)
    }
  }

}
</script>

<style>

</style>
